<div id="executeResult"></div>

<div class="col-md-12">
    {% for i, file in enumerate(files) %}
    <div class="note"> 
        <div class="note-body">
            <div class="note-visited-cnt">
                {% if file.id != None %}
                <a class="item-option dialog-btn" dialog-url="/file/group/list?id={{file.id}}&filetype=xml">移动</a>
                {% end %}
            </div>
            <div class="note-name">
                {% if file.type == "group" %}
                    <img src="/static/image/folder.gif"/>
                {% end %}
                <a href="{{file.url}}">{{file.name}}</a>
            </div>
            
            {% if "raw" in file and file.raw != None %}
                <pre>{{ file.raw }}</pre>
            {% end %}

            {% if "html" in file and file.html != None %}
                {% raw file.html %}
            {% end %}

            {# 快捷命令 #}
            {% if file.command != None %}
                <input type="button" class="btn execute-btn" value="执行" href="{{file.command}}"/>
            {% end %}

            {# 知识库 #}
            {% if file.category == "note" %}
            <div>
                {% if hasattr(file, "priority") and file.priority is not None and file.priority > 0 %}
                    <span class="tag red-bg">置顶</span>
                {% end %}
                {% if file.is_public %}
                    <span class="tag">公开</span>
                {% elif file.creator != None %}
                    <span class="tag">{{file.creator}}</span>
                {% end %}

                {% if file.mtime != None %}
                    <span class="note-last-visit-time">最近更新:{{file.mtime}}</span>
                {% end %}
            </div>
            <div class="note-related">
                <input type="text" data-role="tagsinput" value="{{file.related}}"/>
            </div>
            {% end %}
        </div>
    </div>
    {% end %}
</div>

{% if "page" in globals() %}
    {% init key = "" %}
    {% if key != "" %}
        {# TODO 移动端优化 #}
        <div class="note">
            <div class="note-body">
                <div class="note-name">
                    没找到结果?试试这些吧~
                </div>
                <div class="note-content-short">
                    <br/>
                    <a href="https://www.baidu.com/s?wd={{key}}" target="_blank">百度</a>
                    <a href="https://www.google.com/search?q={{key}}" target="_blank">谷歌</a>
                    <a href="https://www.bing.com/search?q={{key}}" target="_blank">必应</a>
                    {% if _has_login %}
                    <a href="/file/add?key={{key}}">创建"{{key}}"</a>
                    {% end %}
                </div>
            </div>
        </div>
    {% end %}
{% init page_max = 0 %}
{% include mod_pagenation.html %}
<script>
    $(".execute-btn").on("click", function (e) {
        console.log(e);
        var href = $(e.target).attr("href");
        $.get(href, function (responseText) {
            var obj = responseText;
            console.log(obj);
            if (obj.data) {
                $("#executeResult").text(JSON.stringify(obj.data));
            }
        });
    })
</script>

{% end %}
